package 剑指offer;

import java.util.Stack;

public class Offer31_JZ21 {
    public boolean IsPopOrder(int [] pushA,int [] popA) {
        Stack<Integer> stack = new Stack<>();
        int i=0;
        for(int num : pushA) {
            stack.push(num);
            while (!stack.isEmpty() && stack.peek()==popA[i]) {
                stack.pop();
                i++;
            }
        }
        return stack.isEmpty();
    }
}
